<template>
	<!-- 	<uni-table border stripe emptyText="暂无更多数据">
		<uni-tr>
			<uni-th align="left">姓名</uni-th>
			<uni-th align="left">操作</uni-th>
		</uni-tr>
		<uni-tr v-for="item in listData">
			<uni-td>{{ item.childName }} （{{ item.childIdCardNumber }}）</uni-td>
			<uni-td>
				<button size="mini" @click="goToEditLeftBehind(item.id)" to="/pages/data-report/edit-left-behind"
					class="report-button">
					编辑
				</button>
			</uni-td>
		</uni-tr>
	</uni-table> -->
	<view class="uni-section-wrapper">
		<uni-section title="" type="line">
			<uni-list>
				<uni-list-item v-for="item in listData" :title="item.childName + '  ' + item.childIdCardNumber"
					rightText="编辑" link="navigateTo" :to="'/pages/data-report/edit-left-behind?id=' + item.id"
					showArrow />
			</uni-list>
		</uni-section>
		<div class="space"></div>
		<uni-pagination title="标题文字" prev-text="前一页" next-text="后一页" :total="total" :current="current"
			@change="handlePage" />
	</view>
</template>

<script setup>
	import {
		ref
	} from "vue";
	import {
		onShow
	} from '@dcloudio/uni-app';
	import {
		HOST
	} from "../../static/js/const";

	let total = ref(0);
	let current = ref(1);
	let pageSize = ref(5);
	let listData = ref([]);

	const handlePage = (params) => {
		current.value = params.current;
		onQuery()
	}

	const goToEditLeftBehind = (id) => {
		uni.navigateTo({
			url: "/pages/data-report/edit-left-behind?id=" + id, // 页面相对路径（需在 pages.json 注册）
		});
	};

	const onQuery = () => {
		uni.request({
			url: `${HOST}/dir/from/leftBehindChildren/pageSearch`,
			method: 'POST',
			header: {
				'content-type': 'application/json',
				'Authorization': 'Bearer ' + uni.getStorageSync('accessToken')
			},
			data: {
				current: current.value,
				size: pageSize.value,
				data: {
					alarmType: ""
				}
			},
			success: (res) => {
				if (res.data.status === "OK" && res.data.flag) {
					listData.value = res.data.data.records;
					total.value = res.data.data.total;
				} else if (Number(res.data.code) === 401) {
					uni.showToast({
						title: "登录超时",
						icon: "error"
					});
					uni.removeStorageSync('accessToken');
					uni.reLaunch({
						url: '/pages/login/index' // 这里的URL是登录页面的路径
					});
				} else {
					uni.showToast({
						title: res.data.message,
						icon: "error"
					});
				}
			},
			fail: (err) => {
				console.error('请求失败', err);
				uni.showToast({
					title: "连接失败",
					icon: "error"
				});
			}
		});
	}

	onShow(() => {
		onQuery();
	})
</script>

<style lang="scss" scoped>
	/* 隐藏标题栏区域 */
	.uni-section-wrapper::v-deep .uni-section .uni-section-header {
		display: none !important;
	}

	/* 隐藏装饰线（type="line"） */
	.uni-section-wrapper::v-deep .uni-section .uni-section-header__decoration {
		display: none !important;
	}
</style>